package com.central.apps.util;

import com.central.common.util.ToolUtil;


import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

public class StringUtil {
    public static String setString(String old) {
        Map<String, String> map = new HashMap<>();
        map.put("01", "点验数量、外观、型号");
        map.put("02", "查验合格证、出厂质量报告等");
        map.put("03", "查验第三方检验报告");
        map.put("04", "技术指标验证");
        map.put("05", "入所质检");
        String[] olds = old.split(",");
        StringBuffer sb = new StringBuffer("");
        for (String s : olds) {
            if (ToolUtil.isNotEmpty(s)) {
                sb.append(map.get(s)).append(";").append("\n");
            }

        }
        return sb.toString();
    }

    //验证是否是数字型
    public static boolean isNumeric(String str) {
        if (str == null) {
            return false;
        }
        try {
            double d = Double.parseDouble(str);
        } catch (NumberFormatException nfe) {
            return false;
        }
        return true;
    }

    //验证是否是日期型
    public static boolean isDate(String str) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        try {
            dateFormat.parse(str.trim());
        } catch (ParseException pe) {
            return false;
        }
        return true;
    }

    //double转字符串，保留两位小数
    public static String setDouble(double number) {
        //double num = 1.23456789;
        DecimalFormat df = new DecimalFormat("#.00");
        String result = df.format(number);
        return result;
    }
}
